home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / e / amigae33a.lha / E_v3.3a / Src.lha / Src / OOmodules / library / asl.e < prev    next >
Text File  |  1996-05-26  |  7KB  |  310 lines

  1. OPT MODULE
  2.  
  3. MODULE  'oomodules/library',
  4.  
  5.         'asl',
  6.         'libraries/asl',
  7.  
  8.         'other/ecode',
  9.         'dos/dos',
  10.         'dos/dosasl',
  11.         'utility/hooks'
  12.  
  13. CONST MAXPATTERNLENGTH=80,
  14.       MAXFILELENGTH=30,
  15.       MAXDIRLENGTH=255
  16.  
  17. DEF patbuffer,
  18.  
  19. /*
  20.  * The patbuffer variable is used in hookFunc and getFileWithPattern. It holds
  21.  * the pattern the files should match.
  22.  */
  23.  
  24.     temporaryBuffer:PTR TO CHAR -> contains temporary data
  25.  
  26. /*
  27.  * the temporary buffer contains the absolute file name of the file name
  28.  * that was chosen in the last requester.
  29.  */
  30.  
  31. EXPORT OBJECT asl OF library
  32. /****** asl/asl ******************************
  33.  
  34.     NAME
  35.       asl of library
  36.  
  37.     PURPOSE
  38.       Object for handling the asl.library.
  39.  
  40.     ATTRIBUTES
  41.       patbuffer[MAXPATTERNLENGTH]:ARRAY OF CHAR -- buffer to store the file
  42.           pattern in.
  43.  
  44.       lastFileChosen[MAXFILELENGTH]:ARRAY OF CHAR -- buffer to store the name
  45.           of the file that was chosen in the last requester.
  46.  
  47.       lastDirChosen[MAXDIRLENGTH]:ARRAY OF CHAR -- buffer to store the name
  48.           of the directory that was chosen in the last requester.
  49.  
  50.     NOTES
  51.       Not all functions of the asl.library are implemented.
  52.  
  53.     SEE ALSO
  54.         library
  55.  
  56. ********/
  57.   patbuffer[MAXPATTERNLENGTH]:ARRAY OF CHAR,
  58.   lastFileChosen[MAXFILELENGTH]:ARRAY OF CHAR
  59.   lastDirChosen[MAXDIRLENGTH]:ARRAY OF CHAR
  60. ENDOBJECT
  61.  
  62. PROC init() OF asl
  63. /****** reqtools/init ******************************************
  64.  
  65.     NAME 
  66.         init() -- Initialization of the object.
  67.  
  68.     SYNOPSIS
  69.         asl.init()
  70.  
  71.     FUNCTION
  72.         Copies 'SYS:' to the lastDirChosen attribute.
  73.         Sets the library's name and the version to 0. After that the library
  74.         is opened.
  75.  
  76.     SEE ALSO
  77.         open()
  78. ******************************************************************************
  79.  
  80. History
  81.  
  82.  
  83. */
  84.   temporaryBuffer := String(255)
  85.  
  86.   AstrCopy(self.lastDirChosen, 'SYS:')
  87.  
  88.   self.identifier:='asl.library'
  89.   self.version:=0
  90.   self.open()
  91. ENDPROC
  92.  
  93. EXPORT PROC open() OF asl
  94. /****** asl/open ******************************
  95.  
  96.     NAME
  97.         open() of asl -- Open the asl.library.
  98.  
  99.     SYNOPSIS
  100.         asl.open()
  101.  
  102.     FUNCTION
  103.         Open the asl.library. The version to open can be specified in the
  104.         option list you pass to new().
  105.  
  106.     EXCEPTION
  107.         As with all libraries, the exception "lib" is raised when the opening
  108.         failed. The exceptioninfo contains a string that tells this.
  109.  
  110.     NOTES
  111.         The string may be localized in the future.
  112.  
  113.     SEE ALSO
  114.         asl
  115.  
  116. ********/
  117.  
  118.  IF (aslbase:=OpenLibrary(self.identifier,self.version)) = NIL THEN Throw("lib",{aslOpen})
  119.  
  120. ENDPROC
  121.  
  122. EXPORT PROC close() OF asl
  123. /****** asl/close ******************************
  124.  
  125.     NAME
  126.         close() of asl -- Close the library.
  127.  
  128.     SYNOPSIS
  129.         asl.close()
  130.  
  131.     FUNCTION
  132.         Closes the library if it is open.
  133.  
  134.     SEE ALSO
  135.         asl
  136.  
  137. ********/
  138.  
  139.   IF aslbase THEN CloseLibrary(aslbase)
  140.  
  141. ENDPROC
  142.  
  143. PROC end() OF asl
  144. /****** asl/end ******************************
  145.  
  146.     NAME
  147.         end() of asl -- Global destructor.
  148.  
  149.     SYNOPSIS
  150.         asl.end()
  151.  
  152.     FUNCTION
  153.         Frees allocated resources and closes the library.
  154.  
  155.     SEE ALSO
  156.         asl
  157.  
  158. ********/
  159.  
  160.   DisposeLink(temporaryBuffer)
  161.   self.close()
  162.  
  163. ENDPROC
  164.  
  165. PROC hookFunc(type, obj:PTR TO anchorpath, fr)
  166. /****** /hookFunc ******************************
  167.  
  168.     NAME
  169.         hookFunc() -- Hook function for requesters.
  170.  
  171.     SYNOPSIS
  172.         hookFunc(LONG, PTR TO anchorpath, LONG)
  173.  
  174.         hookFunc(type, obj, fr)
  175.  
  176.     FUNCTION
  177.         Used when displaying the file requesters.
  178.  
  179.     NOTES
  180.         Stolen from JRH's rkrm examples. Dunno how it works, so this autodoc
  181.         lacks the input description :-(
  182.  
  183.     SEE ALSO
  184.         getFileWithPattern(), rkrm examples
  185. ********/
  186.   DEF returnvalue
  187.   SELECT type
  188.   CASE FILF_DOMSGFUNC
  189.     -> We got a message meant for the window
  190.     RETURN obj
  191.   CASE FILF_DOWILDFUNC
  192.     -> We got an AnchorPath structure, should the requester display this file?
  193.  
  194.     -> MatchPattern() is a dos.library function that compares a matching
  195.     -> pattern (parsed by the ParsePattern() DOS function) to a string and
  196.     -> returns TRUE if they match.
  197.     returnvalue:=MatchPattern(patbuffer, obj.info.filename)
  198.  
  199.     -> We have to negate MatchPattern()'s return value because the file
  200.     -> requester expects a zero for a match not a TRUE value
  201.     RETURN returnvalue=FALSE
  202.   ENDSELECT
  203. ENDPROC
  204.  
  205. EXPORT PROC getFileWithPattern(pattern:PTR TO CHAR, taglist=NIL) OF asl
  206. /****** asl/getFileWithPattern ******************************
  207.  
  208.     NAME
  209.         getFileWithPattern() of asl -- Get a file that matches the pattern.
  210.  
  211.     SYNOPSIS
  212.         asl.getFileWithPattern(PTR TO CHAR, LONG=NIL)
  213.  
  214.         asl.getFileWithPattern(pattern, taglist)
  215.  
  216.     FUNCTION
  217.         Opens a file requester that displays the files that match the pattern
  218.         provided.
  219.  
  220.     INPUTS
  221.         pattern:PTR TO CHAR -- The pattern of the files that should appear in
  222.             the file list. The usual dos.library wildcards are allowed.
  223.  
  224.         taglist:LONG -- asl tags. See CBM's asl.doc for those.
  225.  
  226.     RESULT
  227.         PTR TO CHAR -- The chosen file or NIL if the user aborted.
  228.  
  229.     NOTES
  230.         The attributes lastFileChosen and lastDirChosen are set by this proc.
  231.  
  232.         Stolen from JRH's rkrm examples.
  233.  
  234.     KNOWN BUGS
  235.         Tries to add a file name even if no file was chosen. Fixed this bug
  236.         (May 26 1996 Gregor Goldbach).
  237.  
  238.     SEE ALSO
  239.         asl/asl, CBM's asl.doc, JRH's rkrm examples
  240.  
  241. ********/
  242. DEF fr:PTR TO filerequester,
  243.     myFunc,
  244.     nulist
  245.  
  246.   ParsePattern(pattern, self.patbuffer, MAXPATTERNLENGTH)
  247.  
  248.   patbuffer := self.patbuffer
  249.  
  250.   fr:=AllocFileRequest()
  251.   -> E-Note: eCodeASLHook() sets up an E PROC for use as an ASL hook function
  252.   myFunc:=eCodeASLHook({hookFunc})
  253.  
  254.   IF myFunc
  255.  
  256.  /*
  257.   * now we have myFunc. we're able to set up the tag list
  258.   */
  259.  
  260.     nulist := List(255)
  261.     ListCopy(nulist, taglist)
  262.     ListAdd(nulist, [ASL_HOOKFUNC, myFunc, ASL_FUNCFLAGS, FILF_DOWILDFUNC OR FILF_DOMSGFUNC OR FILF_SAVE])
  263.  
  264.  
  265. /*
  266.     IF AslRequest(fr, [ASL_DIR,       'SYS:Utilities',
  267. ->                       ASL_WINDOW,    window,
  268.                        ASL_TOPEDGE,   0,
  269.                        ASL_HEIGHT,    200,
  270.                        ASL_HAIL,      'Pick an icon, select save',
  271.                        -> E-Note: use the value returned from aslhook()
  272.                        ASL_HOOKFUNC,  myFunc,
  273.                        ASL_FUNCFLAGS, FILF_DOWILDFUNC OR FILF_DOMSGFUNC
  274.                        ASL_OKTEXT, 'Save',
  275.                        NIL])
  276. */
  277.  
  278.     IF AslRequest(fr, nulist)
  279.  
  280.       AstrCopy(self.lastDirChosen,fr.drawer, IF StrLen(fr.drawer)<MAXDIRLENGTH THEN StrLen(fr.drawer)+1 ELSE MAXDIRLENGTH)
  281.       AstrCopy(self.lastFileChosen,fr.file, IF StrLen(fr.file)<MAXFILELENGTH THEN StrLen(fr.file)+1 ELSE MAXFILELENGTH)
  282.  
  283. /*
  284.       WriteF('PATH=\s FILE=\s\n', fr.drawer, fr.file)
  285.       WriteF('To combine the path and filename, copy the path\n')
  286.       WriteF('to a buffer, add the filename with Dos AddPart().\n')
  287. */
  288.     ENDIF
  289.  
  290.   ENDIF
  291.  
  292.   DisposeLink(nulist)
  293.  
  294.   IF fr THEN FreeFileRequest(fr)
  295.  
  296.   StrCopy(temporaryBuffer, self.lastDirChosen)
  297.   IF self.lastFileChosen[0] THEN AddPart(temporaryBuffer, self.lastFileChosen, 255)
  298.  
  299.   RETURN temporaryBuffer
  300.  
  301. ENDPROC
  302.  
  303.  
  304.  
  305. aslOpen: CHAR 'Unable to open asl.library',0
  306. /*EE folds
  307. -1
  308. 31 29 33 28 36 26 39 18 42 19 45 37 
  309. EE folds*/
  310.